package com.xunyin.modules.redisqueue;

import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.listener.ChannelTopic;
import org.springframework.stereotype.Component;

// 消息发布者
@Component
public class MessagePublisher {

    private final RedisTemplate redisTemplate;
    private final ChannelTopic topic;

    public MessagePublisher(RedisTemplate redisTemplate, ChannelTopic topic) {
        this.redisTemplate = redisTemplate;
        this.topic = topic;
    }

    public void publishMessage(PublishMessage publishMessage) {

        redisTemplate.convertAndSend(topic.getTopic(), publishMessage);
    }

    public void publishMessage1(String message) {

        redisTemplate.convertAndSend(topic.getTopic(), message);
    }

}
